/*
 * Daniel R Padilla
 *
 * Copyright (c) 2008, Daniel R Padilla
 *
 * This copyrighted material is made available to anyone wishing to use, modify,
 * copy, or redistribute it subject to the terms and conditions of the GNU
 * Lesser General Public License, as published by the Free Software Foundation.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
 * or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Lesser General Public License
 * for more details.
 *
 * You should have received a copy of the GNU Lesser General Public License
 * along with this distribution; if not, write to:
 * Free Software Foundation, Inc.
 * 51 Franklin Street, Fifth Floor
 * Boston, MA  02110-1301  USA
 */
package org.databasefacade.table.column.datatype;

import org.databasefacade.translator.Translator;

public abstract class AbstractDataType implements DataType {
    private String sqlType = "";
    private String javaType = "";
    private int length = 0;
    private int precision = 0;
    private int scale = 0;
    private String nullable = "NULL";
    private short columnType = 0;
        
    public void setJavaType(String java) {
    	javaType = java;
    }
    public String getJavaType() {
    	return javaType;
    }
    
    public void setSqlType(Translator translator, DataType type) {
    	sqlType = translator.getDataTypeSQL(type);
    }
    public void setSqlType(String sql) {
    	sqlType = sql;
    }
    public String getSqlType() {
    	return sqlType;
    }
    
    public void setLength(int len) {
    	length=len;
    }
    public int getLength() {
    	return length;
    }
    
    public void setPrecision(int prec) {
    	precision=prec;
    }
    public int getPrecision() {
    	return precision;
    }
    
    public void setScale(int sc) {
    	scale=sc;
    }
    public int getScale() {
    	return scale;
    }
    
    public void setColumnType(short type) {
    	columnType = type;
    }
    public short getColumnType() {
    	return columnType;
    }
    
    public void setNullable(String nill) {
    	nullable=nill;
    }
    public String getNullable() {
    	return nullable;
    }
    
    public DataType getCopy(Translator translator) {
    	DataTypeFactory factory = new DataTypeFactory(translator);
    	DataType target = factory.getInstance(this.getColumnType());
        if (this.getSqlType() != null) {
            target.setSqlType(new String(this.getSqlType()));
        }
        if (this.getJavaType() != null) {
            target.setJavaType(new String(this.getJavaType()));
        }
        if (this.getNullable() != null) {
            target.setNullable(new String(this.getNullable()));
        }
        target.setLength(this.getLength());
        target.setPrecision(this.getPrecision());
        target.setScale(this.getScale());
        return target;
    }
}
